home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / clarion / cw15 / tpw15.z / CTLVIEW.TPW < prev    next >
Text File  |  1995-09-02  |  6KB  |  165 lines

  1. #!----------------------------------------------------------------
  2. #CONTROL(ASCIIBox,'View an ASCII text file in a List Box'),WINDOW,MULTI,HLP('~TPLControlASCIIBox')
  3.        CONTROLS
  4.          LIST,AT(,,150,100),FONT('FixedSys',9,,FONT:regular),USE(?AsciiBox),HVSCROLL,FROM(Queue:ASCII)
  5.        END
  6. #GLOBALDATA
  7. ASCIIFileName        CSTRING(80)
  8. #ENDGLOBALDATA
  9. #LOCALDATA
  10. ASCIIFileSize        LONG
  11. ASCIIBytesThisRead   LONG
  12. ASCIIBytesRead       LONG
  13. ASCIIBytesThisCycle  LONG
  14. ASCIIPercentProgress BYTE
  15. #ENDLOCALDATA
  16. #BOXED('ASCII Box')
  17.   #PROMPT('Description:',@S60),%ASCIIFileDescription
  18.   #PROMPT('File Name to View:',@S80),%ASCIIFile,REQ
  19.   #PROMPT('Display the number of bytes read',CHECK),%DisplayBytesRead,AT(10,,180)
  20.   #PROMPT('Warn the user if the file cannot be found?',CHECK),%ASCIIWarning,DEFAULT(1),AT(10,,180)
  21. #ENDBOXED
  22. #AT(%CustomGlobalDeclarations)
  23.   #FIX(%Driver,'ASCII')
  24.   #PROJECT(%DriverLIB)
  25. #ENDAT
  26. #ATSTART
  27.   #DECLARE(%InstancePrefix)
  28.   #SET(%InstancePrefix,'ASC' & %ActiveTemplateInstance)
  29.   #DECLARE(%ASCIIControl)
  30.   #DECLARE(%ASCIIQueue)
  31.   #FOR(%Control),WHERE(%ControlInstance = %ActiveTemplateInstance)
  32.     #SET(%ASCIIControl,%Control)
  33.     #SET(%ASCIIQueue,EXTRACT(%ControlStatement,'FROM'))
  34.     #SET(%ASCIIQueue,SUB(%ASCIIQueue,6,LEN(%ASCIIQueue)-6))
  35.   #ENDFOR
  36. #ENDAT
  37. #AT(%GatherSymbols)
  38.   #SET(%ProgressWindowRequired,%True)
  39. #ENDAT
  40. #AT(%DataSectionBeforeWindow)
  41. %[20]ASCIIQueue QUEUE
  42.                      STRING(255)
  43.                    END
  44. #SET(%ValueConstruct,%InstancePrefix & ':FileName')
  45. %[20]ValueConstruct STRING(80)
  46. #SET(%ValueConstruct,%InstancePrefix & ':CurrentFileName')
  47. %[20]ValueConstruct STRING(80)
  48. %InstancePrefix:ASCIIFile        FILE,PRE(%InstancePrefix),DRIVER('ASCII'),NAME(ASCIIFileName)
  49.                        RECORD,PRE()
  50. STRING                   STRING(255)
  51.                        END
  52.                      END
  53. #ENDAT
  54. #AT(%RefreshWindowAfterLookup)
  55. #EMBED(%BeforeControlRefresh,'Before Refresh Window for ASCII Box'),%ActiveTemplateInstance,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
  56. #INSERT(%StandardValueAssignment,%InstancePrefix & ':FileName',%ASCIIFile)
  57. IF %InstancePrefix:FileName <> %InstancePrefix:CurrentFileName
  58.   ASCIIFileName = %InstancePrefix:FileName
  59.   DO %InstancePrefix:FillQueue
  60.   %InstancePrefix:CurrentFileName = %InstancePrefix:Filename
  61. END
  62. #EMBED(%AfterControlRefresh,'After Refresh Window for ASCII Box'),%ActiveTemplateInstance,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
  63. #ENDAT
  64. #AT(%ProcedureRoutines)
  65. %InstancePrefix:FillQueue ROUTINE
  66.   FREE(%ASCIIQueue)
  67.   IF NOT ASCIIFileName
  68.     %ASCIIControl{Prop:Disable} = True
  69.     EXIT
  70.   ELSE
  71.     %ASCIIControl{Prop:Disable} = False
  72.   END
  73.   OPEN(%InstancePrefix:ASCIIFile,10h)
  74.   IF ERRORCODE()
  75.     DISABLE(%ASCIIControl)
  76.     #EMBED(%ASCIIBoxFileError,'ASCII Box, File not found'),%ActiveTemplateInstance,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
  77.     #IF(%ASCIIWarning)
  78.     IF StandardWarning(Warn:FileLoadError,%InstancePrefix:FileName)
  79.       EXIT
  80.     END
  81.     #ELSE
  82.     EXIT
  83.     #ENDIF
  84.   ELSE
  85.     ENABLE(%ASCIIControl)
  86.     #EMBED(%ASCIIBoxFileFound,'ASCII Box, File found'),%ActiveTemplateInstance,MAP(%ActiveTemplateInstance,%ActiveTemplateinstanceDescription)
  87.   END
  88.   ASCIIFileSize = BYTES(%InstancePrefix:ASCIIFile)
  89.   IF ASCIIFileSize = 0
  90.     CLOSE(%InstancePrefix:ASCIIFile)
  91.     DISABLE(%ASCIIControl)
  92.     #IF(%ASCIIWarning)
  93.     IF StandardWarning(Warn:FileZeroLength,%InstancePrefix:FileName)
  94.       EXIT
  95.     END
  96.     #ENDIF
  97.     EXIT
  98.   END
  99.   OPEN(ProgressWindow)
  100.   ASCIIPercentProgress = 0
  101.   ASCIIBytesRead = 0
  102.   ProgressWindow{Prop:Text} = 'Reading File'
  103.   Progress:Thermometer = 0
  104.   ?Progress:PctText{Prop:Text} = '0% Completed'
  105.   #IF(SUB(%ASCIIFileDescription,1,1)='!')
  106.     #SET(%ValueConstruct,SUB(%ASCIIFileDescription,2,LEN(%ASCIIFileDescription)-1))
  107.   ?Progress:UserString{Prop:Text} = %ValueConstruct
  108.   #ELSE
  109.   ?Progress:UserString{Prop:Text} = '%ASCIIFileDescription'
  110.   #ENDIF
  111.   ACCEPT
  112.     CASE EVENT()
  113.     OF Event:OpenWindow
  114.       SET(%InstancePrefix:ASCIIFile)
  115.     OF Event:Timer
  116.       ASCIIBytesThisCycle = 0
  117.       LOOP WHILE ASCIIBytesThisCycle < 20000
  118.         NEXT(%InstancePrefix:ASCIIFile)
  119.         IF ERRORCODE()
  120.           LocalResponse = RequestCompleted
  121.           BREAK
  122.         END
  123.         ASCIIBytesThisRead = BYTES(%InstancePrefix:ASCIIFile)
  124.         ASCIIBytesThisCycle += ASCIIBytesThisRead
  125.         ASCIIBytesRead += ASCIIBytesThisRead
  126.         %ASCIIQueue = %InstancePrefix:String
  127.         ADD(%ASCIIQueue)
  128.       END
  129.       IF ASCIIPercentProgress < 100
  130.         ASCIIPercentProgress = (ASCIIBytesRead/ASCIIFileSize)*100
  131.         IF ASCIIPercentProgress > 100
  132.           ASCIIPercentProgress = 100
  133.         END
  134.         IF Progress:Thermometer <> ASCIIPercentProgress THEN
  135.           Progress:Thermometer = ASCIIPercentProgress
  136.   #IF(%DisplayBytesRead)
  137.           ?Progress:PctText{Prop:Text} = FORMAT(ASCIIPercentProgress,@N3) & '% Completed (' & ASCIIBytesRead & ') bytes'
  138.   #ELSE
  139.           ?Progress:PctText{Prop:Text} = FORMAT(ASCIIPercentProgress,@N3) & '% Completed'
  140.   #ENDIF
  141.           DISPLAY(?Progress:Thermometer)
  142.           DISPLAY(?Progress:PctText)
  143.         END
  144.       END
  145.       IF LocalResponse = RequestCompleted
  146.         LocalResponse = RequestCancelled
  147.         POST(Event:CloseWindow)
  148.       END
  149.     END
  150.     CASE FIELD()
  151.     OF ?Progress:Cancel
  152.       CASE EVENT()
  153.       OF Event:Accepted
  154.         IF StandardWarning(Warn:ConfirmCancelLoad,%InstancePrefix:FileName)=Button:OK
  155.           POST(Event:CloseWindow)
  156.         END
  157.       END
  158.     END
  159.   END
  160.   CLOSE(ProgressWindow)
  161.   CLOSE(%InstancePrefix:ASCIIFile)
  162. #ENDAT
  163. #!----------------------------------------------------------------
  164. #INCLUDE('CtlViewA.TPW')
  165.